package cn.edu.guet.controller;

import cn.edu.guet.bean.collectpostbean.collectpost;
import cn.edu.guet.service.collectpost.collectpostseritf;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class collectpostController {
    @Autowired
    private cn.edu.guet.service.collectpost.collectpostseritf collectpostseritf;
    @RequestMapping("html/collectposthtml/maincollect.do")
    public String mainperson( HttpServletRequest request){
        String userid=""+request.getSession().getAttribute("userid");
        request.setAttribute("userid",userid);
        return "html/collectposthtml/maincollect";
    }
    @RequestMapping("html/collectposthtml/cyemian.do")
    public String cyemian(String cyemian,String userid,HttpServletRequest request){
        request.setAttribute("userid",userid);
        return "html/collectposthtml/"+cyemian;
    }

//显示收藏贴子
    @RequestMapping("html/collectposthtml/sctz.do")
    @ResponseBody
    public List<collectpost> getSCTZ(String userid, int page){
        int count=collectpostseritf.getSCTZCount(userid);
        collectpost collectpost=new collectpost();
        collectpost.setUserid(userid);
        collectpost.setPage(page);
        List<cn.edu.guet.bean.collectpostbean.collectpost> list=collectpostseritf.getSCTZ(collectpost);
        for (int i=0;i<list.size();i++){
            list.get(i).setCount(count);
        }
        return list;
    }
    //删除收藏贴子
    @RequestMapping("html/collectposthtml/deletesctz.do")
    public String  deleteAllSCTZ(String userid,String deleteArry,int page){
        String index[]=deleteArry.split(",");
        for(int i=0;i<index.length;i++){
            collectpostseritf.deleteSCTZ(userid, index[i]);
        }
        return "forward:sctz.do?userid="+userid+"&page="+page;

    }
}
